*Authors: Elena McLean and Mitch Radtke
*Project: Table 2 
*Date Last Modified: August 29, 2016

*Importing Data

use "E:\isa_mclean_radtke_replication.dta", clear

*Set system directory

sysdir set PLUS "E:\Stata12\ado\plus"
sysdir set PERSONAL "E:\Stata12\ado\personal"

*Model 1: Threat Logit 

capture program drop surv3
program surv3, rclass

logit fail sanctepisode2_target  targ_mid  targ_gdppc_log targ_pop_log targ_gdpgrowth targ_civ_war targetdem age lnten dem_ln_tenure prevtimesinoffice irr_entry failyears failspline* if count_targ==1 
predict pf
sort target year pf
by target year: replace pf=pf[_n-1] if pf==.
sort sender target year
by sender target: gen pf_lag=pf[_n-1]

gen pf_SScore=pf_lag*ideal_diff

logit hthreat pf_lag ideal_diff pf_SScore senderdem targetdem lnSendGDP lnTargGDP LnDyadTrade lndist lncapratio mid ColdWar hyears hspline* if exclude2==0 & polirel==1

capture drop pf pf_lag pf_SScore
end

bs, reps(100) seed(1987) notable strata(sender): surv3
est store t1

matrix list e(b)
matrix list e(se)

*Model 2: Sanction Logit 

capture program drop surv2
program surv2, rclass

logit fail sanctepisode2_target  targ_mid  targ_gdppc_log targ_pop_log targ_gdpgrowth targ_civ_war targetdem age lnten dem_ln_tenure prevtimesinoffice irr_entry failyears failspline* if count_targ==1 
predict pf
sort target year pf
by target year: replace pf=pf[_n-1] if pf==.
sort sender target year
by sender target: gen pf_lag=pf[_n-1]

gen pf_SScore=pf_lag*ideal_diff

logit hsanct pf_lag ideal_diff pf_SScore  targetdem senderdem lndist lncapratio STTradeShare TSTradeShare mid ColdWar if hthreat==1 & exclude2==0 & polirel==1

capture drop pf pf_lag pf_SScore 
end

bs, reps(100) seed(1987) nodrop notable strata(sender): surv2 
est store t2

*Model 3: Heckman Probit 

capture program drop surv2
program surv2, rclass

logit fail sanctepisode2_target  targ_mid  targ_gdppc_log targ_pop_log targ_gdpgrowth targ_civ_war targetdem age lnten dem_ln_tenure prevtimesinoffice irr_entry failyears failspline* if count_targ==1 
predict pf
sort target year pf
by target year: replace pf=pf[_n-1] if pf==.
sort sender target year
by sender target: gen pf_lag=pf[_n-1]

gen pf_SScore=pf_lag*ideal_diff

heckprobit hsanct pf_lag ideal_diff pf_SScore senderdem targetdem lndist lncapratio STTradeShare TSTradeShare mid ColdWar if polirel==1 & exclude2==0, sel(hthreat=pf_lag ideal_diff pf_SScore senderdem targetdem lnSendGDP lnTargGDP LnDyadTrade lndist lncapratio mid ColdWar hyears hspline*)

capture drop pf pf_lag pf_SScore 
end

bs, reps(100) seed(1987) nodrop notable strata(sender): surv2 
est store t3

*Model 4:  Sartori 

capture program drop surv
program surv, rclass

set maxiter 30
preserve

logit fail sanctepisode2_target  targ_mid  targ_gdppc_log targ_pop_log targ_gdpgrowth targ_civ_war targetdem age lnten dem_ln_tenure prevtimesinoffice irr_entry failyears failspline* if count_targ==1 
predict pf
sort target year pf
by target year: replace pf=pf[_n-1] if pf==.
sort sender target year
by sender target: gen pf_lag=pf[_n-1]

gen pf_SScore=pf_lag*ideal_diff

keep if polirelev==1 & exclude2==0

sartsel sart_dv_h pf_lag ideal_diff pf_SScore targetdem senderdem LnDyadTrade mid ColdWar lndist lncapratio 

capture drop pf pf_lag pf_SScore
restore
end
bs, reps(175) seed(1987) reject(e(converged)!=1) notable nodrop strata(sender): surv
est store t4

*Output to Word
#delimit;
esttab t1 t2 t3 t4 using "E:\Table2.rtf", replace addnote("Standard errors in parentheses. 100 bootstrap replications. Stratified by the sender country") title("Results of bootstrap estimation of sanction threats") starlevels(* 0.10 ** 0.05) nonumbers mlabels("Threat Logit" "Sanction Logit"  "Heckman Probit" "Sartori Estimator") legend cells (b(star fmt(2)) se(par fmt(2))) stats(N ll chi2, 
labels("Observations" "Log likelihood" "Wald chi2")) coeflabels(targetdem "Democratic Target" senderdem "Democratic Sender" lnSendGDP "Logged Sender GDP" LnDyadTrade "Logged Dyadic Trade" lnTargGDP "Logged Target GDP" lncapratio "Logged Capability Ratio" ColdWar
"Cold War" STTradeShare "Target's Trade Dependence" TSTradeShare "Sender's Trade Dependence" pf_lag "Predicted Leader Failure" ideal_diff "Ideal Point Deviation" pf_SScore "Ideal Point Deviation*Predicted Leader Failure" lndist "Logged Distance" SenderTradeOpen
"Sender's Trade Openness" TargetTradeOpen "Target's Trade Openness" mid "Militarized Interstate Dispute" hyears "Peace Years" hspline1 "Cubic Spline 1" hspline2 "Cubic Spline 2" hspline3 "Cubic Spline 3" _cons "Constant") varwidth(30) collabels(" ");
